/*
 * Copyright (c) 2009, Servoy-stuff
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 * http://www.fsf.org/licensing/licenses/lgpl.txt
 */
package net.stuff.servoy.beans.slider;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.io.Serializable;

import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

import net.stuff.servoy.beans.slider.swing.ServoySwingSlider;
import net.stuff.servoy.beans.slider.wicket.ServoyWicketSlider;


import com.servoy.j2db.IServoyBeanFactory;
import com.servoy.j2db.plugins.IClientPluginAccess;
import com.servoy.j2db.ui.IComponent;

/**
 * 
 * @author Servoy Stuff
 * http://www.servoy-stuff.net/
 */
public class ServoySlider implements IServoyBeanFactory, Serializable {
	
	private static final long serialVersionUID = 1L;
	private IServoySliderBean component = new ServoySwingSlider();

	private Color background;
	private Border border;
	private boolean focusable = true;
	private Font font;
	private Color foreground;
	private boolean inverted;
	private boolean opaque = true;
	private int orientation;
	private boolean paintLabels;
	private boolean paintTicks = true;
	private boolean paintTrack = true;
	private boolean snapToTicks = false;
	private Point location;
	private String name;
	private Dimension size = new Dimension(200,30);
	
	private String dataProviderID;
	private String toolTipMessage;

	private int majorTicks = 50;
	private int minorTicks = 10;
	private int minimumValue = 0;
	private int maximumValue = 100;
	private int currentValue = 0;

	private int precision = 2;
	private boolean usingDecimals;
	private String webStyleType = IServoySliderBean.LUNA_STYLE;
	
	private String onDataChange;

	
	/* (non-Javadoc)
	 * @see com.servoy.j2db.IServoyBeanFactory#getBeanInstance(int, com.servoy.j2db.plugins.IClientPluginAccess, java.lang.Object[])
	 */
	public IComponent getBeanInstance(int appMode,
			IClientPluginAccess app,
			Object[] paramArrayOfObject) {
		if (appMode == IClientPluginAccess.WEB_CLIENT) {
			String id = (String)paramArrayOfObject[0];
			component = new ServoyWicketSlider(id, webStyleType);
			setBackground((background == null) ? Color.white : background);
			setForeground((foreground == null) ? Color.black : foreground);
			setBorder((border == null) ? new EtchedBorder(1) : border);
		}
		initComponent(app);
		return component;
	}

	/**
	 * @param app
	 */
	private void initComponent(IClientPluginAccess app) {
		component.initialize(app);
		setWebStyleType(webStyleType);
		setFocusable(focusable);
		setMinorTicks(minorTicks);
		setMajorTicks(majorTicks);
		setMaximumValue(maximumValue);
		setMinimumValue(minimumValue);
		setOpaque(opaque);
		setPaintTicks(paintTicks);
		setPaintLabels(paintLabels);
		setPaintTrack(paintTrack);
		setSnapToTicks(snapToTicks);
		setCurrentValue(currentValue);
		setSize(size);
		setInverted(inverted);
		setPrecision(precision);
		setOrientation(orientation);
		setUsingDecimals(usingDecimals);
		setDataProviderID(dataProviderID);
		setToolTipMessage(toolTipMessage);
		setOnDataChange(onDataChange);
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.persistence.Zdb#getName()
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
		if (component != null) {
			component.setName(name);
		}
	}

	/**
	 * @return the background
	 */
	public Color getBackground() {
		return this.background;
	}

	/**
	 * @param background the background to set
	 */
	public void setBackground(Color background) {
		this.background = background;
		if (component != null) {
			component.setBackground(background);
		}
	}

	/**
	 * @return the border
	 */
	public Border getBorder() {
		return this.border;
	}

	/**
	 * @param border the border to set
	 */
	public void setBorder(Border border) {
		this.border = border;
		if (component != null) {
			component.setBorder(border);
		}
	}

	/**
	 * @return the focusable
	 */
	public boolean isFocusable() {
		return this.focusable;
	}

	/**
	 * @param focusable the focusable to set
	 */
	public void setFocusable(boolean focusable) {
		this.focusable = focusable;
		if (component != null) {
			component.setFocusable(focusable);
		}
	}

	/**
	 * @return the font
	 */
	public Font getFont() {
		return this.font;
	}

	/**
	 * @param font the font to set
	 */
	public void setFont(Font font) {
		this.font = font;
		if (component != null) {
			component.setFont(font);
		}
	}

	/**
	 * @return the foreground
	 */
	public Color getForeground() {
		return this.foreground;
	}

	/**
	 * @param foreground the foreground to set
	 */
	public void setForeground(Color foreground) {
		this.foreground = foreground;
		if (component != null) {
			component.setForeground(foreground);
		}
	}

	/**
	 * @return the inverted
	 */
	public boolean getInverted() {
		return this.inverted;
	}

	/**
	 * @param inverted the inverted to set
	 */
	public void setInverted(boolean inverted) {
		this.inverted = inverted;
		if (component != null) {
			component.setInverted(inverted);
		}
	}

	/**
	 * @return the majorTicks
	 */
	public int getMajorTicks() {
		return this.majorTicks;
	}

	/**
	 * @param majorTicks the majorTicks to set
	 */
	public void setMajorTicks(int majorTicks) {
		this.majorTicks = majorTicks;
		if (component != null) {
			component.setMajorTicks(majorTicks);
		}
	}

	/**
	 * @return the maximumValue
	 */
	public int getMaximumValue() {
		return this.maximumValue;
	}

	/**
	 * @param maximumValue the maximumValue to set
	 */
	public void setMaximumValue(int maximumValue) {
		this.maximumValue = maximumValue;
		if (component != null) {
			component.setMaximumValue(maximumValue);
		}
	}

	/**
	 * @return the minimumValue
	 */
	public int getMinimumValue() {
		return this.minimumValue;
	}

	/**
	 * @param minimumValue the minimumValue to set
	 */
	public void setMinimumValue(int minimumValue) {
		this.minimumValue = minimumValue;
		if (component != null) {
			component.setMinimumValue(minimumValue);
		}
	}

	/**
	 * @return the minorTicks
	 */
	public int getMinorTicks() {
		return this.minorTicks;
	}

	/**
	 * @param minorTicks the minorTicks to set
	 */
	public void setMinorTicks(int minorTicks) {
		this.minorTicks = minorTicks;
		if (component != null) {
			component.setMinorTicks(minorTicks);
		}
	}

	/**
	 * @return the opaque
	 */
	public boolean isOpaque() {
		return this.opaque;
	}

	/**
	 * @param opaque the opaque to set
	 */
	public void setOpaque(boolean opaque) {
		this.opaque = opaque;
		if (component != null) {
			component.setOpaque(opaque);
		}
	}

	/**
	 * @return the orientation
	 */
	public int getOrientation() {
		return this.orientation;
	}

	/**
	 * @param orientation the orientation to set
	 */
	public void setOrientation(int orientation) {
		this.orientation = orientation;
		if (component != null) {
			component.setOrientation(orientation);
		}
	}

	/**
	 * @return the paintLabels
	 */
	public boolean getPaintLabels() {
		return this.paintLabels;
	}

	/**
	 * @param paintLabels the paintLabels to set
	 */
	public void setPaintLabels(boolean paintLabels) {
		this.paintLabels = paintLabels;
		if (component != null) {
			component.setPaintLabels(paintLabels);
		}
	}

	/**
	 * @return the paintTicks
	 */
	public boolean getPaintTicks() {
		return this.paintTicks;
	}

	/**
	 * @param paintTicks the paintTicks to set
	 */
	public void setPaintTicks(boolean paintTicks) {
		this.paintTicks = paintTicks;
		if (component != null) {
			component.setPaintTicks(paintTicks);
		}
	}

	/**
	 * @return the paintTrack
	 */
	public boolean getPaintTrack() {
		return this.paintTrack;
	}

	/**
	 * @param paintTrack the paintTrack to set
	 */
	public void setPaintTrack(boolean paintTrack) {
		this.paintTrack = paintTrack;
		if (component != null) {
			component.setPaintTrack(paintTrack);
		}
	}

	/**
	 * @return the snapToTicks
	 */
	public boolean getSnapToTicks() {
		return this.snapToTicks;
	}

	/**
	 * @param snapToTicks the snapToTicks to set
	 */
	public void setSnapToTicks(boolean snapToTicks) {
		this.snapToTicks = snapToTicks;
		if (component != null) {
			component.setSnapToTicks(snapToTicks);
		}
	}

	/**
	 * @return the toolTipMessage
	 */
	public String getToolTipMessage() {
		return this.toolTipMessage;
	}

	/**
	 * @param toolTipMessage the toolTipMessage to set
	 */
	public void setToolTipMessage(String toolTipMessage) {
		this.toolTipMessage = toolTipMessage;
		if (component != null) {
			component.setToolTipMessage(toolTipMessage);
		}
	}

	/**
	 * @return the currentValue
	 */
	public int getCurrentValue() {
		return this.currentValue;
	}

	/**
	 * @param currentValue the currentValue to set
	 */
	public void setCurrentValue(int currentValue) {
		this.currentValue = currentValue;
		if (component != null) {
			component.setCurrentValue(currentValue);
		}
	}

	/**
	 * @return the location
	 */
	public Point getLocation() {
		return this.location;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(Point location) {
		this.location = location;
		if (component != null && location != null) {
			component.setLocation(location);
		}
	}

	/**
	 * @return the size
	 */
	public Dimension getSize() {
		return this.size;
	}

	/**
	 * @param size the size to set
	 */
	public void setSize(Dimension size) {
		this.size = size;
		if (component != null && size != null) {
			component.setSize(size);
		}
	}

	/**
	 * @return the dataProviderID
	 */
	public String getDataProviderID() {
		return this.dataProviderID;
	}

	/**
	 * @param dataProviderID the dataProviderID to set
	 */
	public void setDataProviderID(String dataProviderID) {
		this.dataProviderID = dataProviderID;
		if (component != null) {
			component.setDataProviderID(dataProviderID);
		}
	}

	/**
	 * @return the precision
	 */
	public int getPrecision() {
		return this.precision;
	}

	/**
	 * @param precision the precision to set
	 */
	public void setPrecision(int precision) {
		this.precision = precision;
		if (component != null) {
			component.setPrecision(precision);
		}
	}

	/**
	 * @return the usingDecimals
	 */
	public boolean isUsingDecimals() {
		return this.usingDecimals;
	}

	/**
	 * @param usingDecimals the usingDecimals to set
	 */
	public void setUsingDecimals(boolean usingDecimals) {
		this.usingDecimals = usingDecimals;
		if (component != null) {
			component.setUsingDecimals(usingDecimals);
		}
	}

	/**
	 * @return the webStyleType
	 */
	public String getWebStyleType() {
		return this.webStyleType;
	}

	/**
	 * @param webStyleType the webStyleType to set
	 */
	public void setWebStyleType(String webStyleType) {
		this.webStyleType = webStyleType;
		if (component != null) {
			component.setWebStyleType(webStyleType);
		}
	}

	/**
	 * @return the onDataChange
	 */
	public String getOnDataChange() {
		return this.onDataChange;
	}

	/**
	 * @param onDataChange the onDataChange to set
	 */
	public void setOnDataChange(String onDataChange) {
		this.onDataChange = onDataChange;
		if (component != null) {
			component.setOnDataChange(onDataChange);
		}
	}

}
